<!--
 * @Descripttion: 小程序配置
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-11-19 18:39:11
-->
<template>
  <div class="lb-sys-sproconfig">
    <top-nav></top-nav>
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="configForm"
        :rules="configFormRules"
        ref="configForm"
        label-width="140px"
        class="config-form"
      >
        <el-form-item label="Appid" prop="appid">
          <el-input
            v-model="configForm.appid"
            placeholder="请输入Appid"
          ></el-input>
          <lb-tool-tips
            >请输入小程序Appid，输入错误会影响小程序的正常使用，谨慎修改</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="Appsecret" prop="app_secret">
          <el-input
            v-model="configForm.app_secret"
            placeholder="请输入Appsecret"
          ></el-input>
          <lb-tool-tips
            >请输入小程序Appsecret，输入错误会影响小程序的正常使用，谨慎修改</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="小程序名" prop="mini_app_name">
          <el-input
            v-model="configForm.mini_app_name"
            placeholder="请输入小程序名"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo">{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      configForm: {
        appid: '',
        app_secret: '',
        mini_app_name: ''
      },
      configFormRules: {
        appid: { required: true, type: 'string', message: '请输入Appid', trigger: 'blur' },
        app_secret: { required: true, type: 'string', message: '请输入Appsecret', trigger: 'blur' },
        mini_app_name: { required: true, type: 'string', message: '请输入小程序名', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    getFormInfo () {
      this.$api.getAppminiConfigInfo().then(res => {
        console.log(res)
        if (res.code === 200) {
          this.configForm = {
            appid: res.data.appid,
            app_secret: res.data.app_secret,
            mini_app_name: res.data.mini_app_name
          }
        }
      })
    },
    submitFormInfo () {
      this.$refs['configForm'].validate(valid => {
        if (valid) {
          let { configForm } = this
          console.log(configForm)
          this.$api.setAppminiConfigInfo({ app_config: configForm }).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-sys-sproconfig {
  width: 100%;
  .config-form {
    .el-input {
      width: 300px;
    }
  }
}
</style>
